﻿using Autodesk.AutoCAD.DatabaseServices;
namespace ChangDiTools.Tool {
    public static class DimStylesTools {
        /// <summary>
        /// 创建一个新的标注样式
        /// </summary>
        /// <param name="db">数据库对象</param>
        /// <param name="styleName">标注样式名</param>
        /// <returns>返回新建的标注样式的ObjectID</returns>
        public static ObjectId AddDimStyle(this Database db, string styleName) {
            //打开标注样式表
            DimStyleTable dst = db.DimStyleTableId.GetObject(OpenMode.ForRead) as DimStyleTable;
            if (!dst.Has(styleName))//如果不存在名为styleName的标注样式，则新建一个标注样式
            {//定义一个新的标注样式记录
                DimStyleTableRecord dstr = new DimStyleTableRecord() { Name = styleName };
                dst.UpgradeOpen();
                dst.Add(dstr);//将标注样式表记录的信息添加到标注样式表中
                //把标注样式表记录添加到事务处理中
                db.TransactionManager.AddNewlyCreatedDBObject(dstr, true);
                dst.DowngradeOpen();
            }
            //返回新添加的标注样式记录的ObjectID
            return dst[styleName];
        }
    }
}
